#include "projectile.h"

// constructor
Projectile::Projectile(Vector p, Vector d, GLfloat v, double t)
{
	position = p;
	direction = d;
	velocity = v;
	time = t;

	box.setPosition(p);
}

bool Projectile::isActive()
{
	return ((glfwGetTime() - time) < 2.0);
}

void Projectile::draw()
{
	box.setPosition(position);
	box.draw();	
}

void Projectile::update()
{
	if(velocity != 0)
	{
		GLfloat xr = (direction.x / 180 * 3.141592654f);
		position.y -= (GLfloat)sin(xr) * velocity;
		GLfloat h = (GLfloat)cos(xr) * velocity;

		GLfloat yr = (direction.y / 180 * 3.141592654f);
		position.x += (GLfloat)sin(yr) * h;
		position.z -= (GLfloat)cos(yr) * h;
	}
}
